/**
 * @Author: code.rookie
 * @ClassName: NumberOfLslands
 * @PACKAGE_NAME: PACKAGE_NAME
 * @Version: 1
 * @Description 200. 岛屿数量
 */
public class NumberOfLslands {
    public int numIslands(char[][] grid) {
        int rLen=grid.length;
        int cLen=grid[0].length;
        int count=0;
        if(grid.length==0){
            return 0;
        }
        for(int i=0;i<rLen;i++){
            for(int j=0;j<cLen;j++){
                if(grid[i][j]=='1'){
                    dfs(grid,i,j);
                    count++;
                }
            }
        }
        return count;

    }
    public void dfs(char[][]grid,int r,int c){
        int rLen=grid.length;
        int cLen=grid[0].length;
        if(r<0||c<0||r>=rLen||c>=cLen||grid[r][c]=='0'){
            return;
        }
        grid[r][c]='0';
        dfs(grid,r-1,c);
        dfs(grid,r+1,c);
        dfs(grid,r,c-1);
        dfs(grid,r,c+1);
    }
}
